package com.cindata

import com.cindata.dictionary.*

class ContactSurveyReport
{
    String serialNumber
    //业务流水号

    ContactSurvey contact
    //主借款人

    String stage = "已申请"
    String status = "Pending"

    // 贷款申请概要
    BigDecimal loansAmount
    // 贷款金额
    Integer loansDuration
    // 贷款期限
    BigDecimal acceptableLoansAmount
    // 可贷金额
    Date applicationDate
    // 申请日期
    Date startDate
    // 贷款开始日期
    Date endDate
    // 贷款截止日期
    Boolean isCombinationLoans
    // 是否组合贷款
    BigDecimal depositBaseOnCurrent
    // 公积金月还款额（元）
    BigDecimal depositAmountOnCurrent
    // 月总还款额（元）
    RepaymentModeDict starRepaymentMode
    // 还款方式
    LoanMethodDict loanMethod
    // 放款方式
    String guaranteeInstitution
    // 担保机构
    String loanRecipient
    // 受理人
    String advanceLoanStage
    // 提前放款环节：抵押回执环节,房产证完税环节,房产证（新证）环节,其他
    String housingLoansAccount
    // 供楼账号
    String loansBank
    // 放款银行

    // 家庭成员收入能力检查记录
    BigDecimal coOwnersMonTotalIncome
    // 税后收入月均

    // 房产信息
    String sourceAddress
    // 交易房屋地址
    BigDecimal sourceBuildArea
    // 建筑面积
    String houseOwner
    // 抵押物所有人
    Integer houseAge
    // 房屋楼龄
    BigDecimal transactionPrice
    // 交易价格
    BigDecimal firstPayment
    // 首付款
    BigDecimal firstPaymentRatio
    // 首付比例
    String orientation
    // 朝向
    BigDecimal evaluateTotalPrice
    // 评估总价
    BigDecimal evaluateUnitPrice
    // 评估单价
    String isPriceReasonable
    // 价格合理性判断
    String houseNature
    // 房屋性质
    String houseType
    // 房屋类型
    String finalPayeeOfLoans
    // 贷款最终收款人
    String ohterPayeeOfLoans
    // 其他收款人
    Date evaluateDate
    // 最新评估日期
    String evaluateAccount
    // 初次评估机构
    String evaluateReportNumber
    // 评估报告编号
    String houseRealSituationRecord
    // 抵押物实地查看记录

    // 贷款风险评估
    Integer loanNumber
    // 贷款套数
    BigDecimal commonExpendPrice
    // 所有人月均支出
    BigDecimal commonTotalRepaymentPrice
    // 月均还款总金额
    BigDecimal expenditureIncomeRatio
    // 所有人支出收入占比
    BigDecimal mortgageRate
    // 抵押率
    String mortgageWarningMemo
    // 贷款风险揭示

    // 贷款调查意见
    String mortgageRatio
    // 利率：公积金贷款基准利率，公积金贷款基准利率上浮10%
    String mortgageRejectReason
    // 否决原因

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    SortedSet contacts

    static belongsTo = [account: Account]

    static hasMany = [contacts: ContactSurvey]

    static constraints = {
        serialNumber nullable: true, blank: true
        stage inList: ['已申请', '已审核']
        status inList: ['Completed', 'Failed', 'Pending']

        contact nullable: true, blank: true

        // 贷款申请概要
        loansAmount nullable: true, blank: true
        loansDuration nullable: true, blank: true
        acceptableLoansAmount nullable: true, blank: true
        applicationDate nullable: true, blank: true
        startDate nullable: true, blank: true
        endDate nullable: true, blank: true
        isCombinationLoans nullable: true, blank: true
        depositBaseOnCurrent nullable: true, blank: true
        depositAmountOnCurrent nullable: true, blank: true
        starRepaymentMode nullable: true, blank: true
        loanMethod nullable: true, blank: true
        guaranteeInstitution nullable: true, blank: true
        loanRecipient nullable: true, blank: true
        advanceLoanStage nullable: true, blank: true
        advanceLoanStage inList: ['抵押回执环节', '房产证完税环节', '房产证（新证）环节', '其他']
        housingLoansAccount nullable: true, blank: true
        loansBank nullable: true, blank: true



        // 家庭成员收入能力检查记录
        coOwnersMonTotalIncome nullable: true, blank: true


        // 房产信息
        sourceAddress nullable: true, blank: true
        sourceBuildArea nullable: true, blank: true
        houseOwner nullable: true, blank: true
        houseAge nullable: true, blank: true
        transactionPrice nullable: true, blank: true
        firstPayment nullable: true, blank: true
        firstPaymentRatio nullable: true, blank: true
        orientation nullable: true, blank: true
        evaluateTotalPrice nullable: true, blank: true
        evaluateUnitPrice nullable: true, blank: true
        isPriceReasonable nullable: true, blank: true
        houseNature nullable: true, blank: true
        houseType nullable: true, blank: true
        finalPayeeOfLoans nullable: true, blank: true
        ohterPayeeOfLoans nullable: true, blank: true
        evaluateDate nullable: true, blank: true
        evaluateAccount nullable: true, blank: true
        evaluateReportNumber nullable: true, blank: true
        houseRealSituationRecord nullable: true, blank: true

        // 贷款风险评估
        loanNumber nullable: true, blank: true
        commonExpendPrice nullable: true, blank: true
        commonTotalRepaymentPrice nullable: true, blank: true
        expenditureIncomeRatio nullable: true, blank: true
        mortgageRate nullable: true, blank: true
        mortgageWarningMemo nullable: true, blank: true

        // 贷款调查意见
        mortgageRatio nullable: true, blank: true
        mortgageRejectReason nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        //业务流水编号
        String charset = (('A'..'Z') + ('0'..'9')).join()
        String s1 = org.apache.commons.lang.RandomStringUtils.random(3, charset)
        String s2 = org.apache.commons.lang.RandomStringUtils.random(3, charset)
        String s3 = org.apache.commons.lang.RandomStringUtils.random(3, charset)
        serialNumber = "${s1}-${s2}-${s3}"

        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
